import { configure, makeAutoObservable } from 'mobx';
import Taro from '@tarojs/taro';

configure({
  enforceActions: 'always'
});

class SocketStore {
  constructor() {
    makeAutoObservable(this, {}, {autoBind: true});
  }

  /**
   * websocket实例
   */
  websocketInstance: Taro.SocketTask | any;

  /**
   * 设置 websocket 实例
   * @param instance
   */
  setWebsocketInstance(instance: Taro.SocketTask) {
    this.websocketInstance = instance;
  }

  /**
   * 清除 websocket 实例
   */
  clearWebsocketInstance() {
    this.websocketInstance = null;
  }
}

const socketStore = new SocketStore();

export default socketStore;